package no.rodland.acc.interceptors;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

import java.util.Map;

/**
 *
 */
public class SessionInterceptor implements Interceptor {
    public static final String LOGIN_ACTION = "login";

    private static final long serialVersionUID = 2958794432013020369L;
    public static final String LOGGED_IN = "loggedin";

    @Override
    public void destroy() {
    }

    @Override
    public void init() {
    }

    @Override
    public String intercept(ActionInvocation invocation) throws Exception {
        Map<String, Object> session = invocation.getInvocationContext().getSession();
        if (!session.containsKey(LOGGED_IN)) {
//            return LOGIN_ACTION;
            return invocation.invoke();
        } else {
            return invocation.invoke();
        }
    }
}
